There's no danger on walking alone at any time. Most streets are very busy till late night. Respect the locals and you will be respected. Crime is nearly non-existent, even if some of the neighborhoods of the city may look shabby or feel dangerous.
Expect some hassle in the souk medina and this is most normal. Merchants always try to show their goods/shops and see what you like. You have to get into the spirit to enjoy, always be nice and have a smile on your face. Even if sometimes annoying, this is absolutely not dangerous.
Women may want to avoid the red light area in the north west of the medina, reached through two overlapping walls which screen that street from the rest of the medina. Single women walking alone may be stared at, but, again, this is not dangerous, but rather a curiosity of some local men.
Most people who come up and speak English to you in the streets will be hoping to sell you something, no risk but end the conversation quickly to avoid them getting indignant when you dont buy, a simple 'non, merci' should suffice.